﻿(function () {
    "use strict";

    var projects = new WinJS.Binding.List();

    WinJS.UI.Pages.define("/pages/project/projects/projects.html", {
        ready: function (element, options) {
            element.querySelector('#ListView').addEventListener('iteminvoked', function (e) {
                //WinJS.Navigation.navigate('/pages/calendar/weekCalendar/weekCalendar.html', { item: e.detail.itemPromise._value.data });
            });
            initPage();
            
            document.querySelector("#firstSubHeader").addEventListener("click", function () {
                DateUtility.CurrentYear--;
                initPage();
            });
            document.querySelector("#thirdSubHeader").addEventListener("click", function () {
                DateUtility.CurrentYear++;
                initPage();
            });

            document.querySelector("#cmdAdd").addEventListener("click", function () {
                // Cacher la div win-appbarclickeater revient à cacher le appBar, ceci ne se fait pas automatiquement.
                document.querySelector(".win-appbarclickeater").style.display = "none";
                WinJS.Navigation.navigate('/pages/project/addProject/addProject.html');
            });
            
        }
    });


    var goToTeamProjectPage = function (self) {
        WinJS.Navigation.navigate('/pages/project/teamProject/teamProject.html');
    }
    
    var goToEditPage = function (self) {
        WinJS.Navigation.navigate('/pages/project/editProject/editProject.html');
    }

    var initPage = function(){
        var date = new Date(DateUtility.CurrentYear, DateUtility.CurrentMonth, DateUtility.CurrentDay);

        projects.splice(0, projects.length);
        getElements();

        document.querySelector("#secondSubHeader").innerText = date.toString("yyyy");
    }
    

    var getElements = function () {
        var i = 0;
        for (i = 0; i < 100; i++) {
            projects.push({ projectName: "ADP" });
        }
    }

    var publicMembres = {
        projects: projects,
        goToTeamProjectPage: goToTeamProjectPage,
        goToEditPage: goToEditPage
    };


    WinJS.Namespace.define("Projects", publicMembres);

})();
